[XEND] Hook in utilisation statistics into Xen API calls.
authorAlastair Tse <atse@xensource.com>
Fri, 26 Jan 2007 15:45:51 +0000 (15:45 +0000)
committerAlastair Tse <atse@xensource.com>
Fri, 26 Jan 2007 15:45:51 +0000 (15:45 +0000)
Change PIF to be indexed by device name rather than the interface
number.

Signed-off-by: Alastair Tse <atse@xensource.com>
tools/python/xen/xend/XendAPI.py
tools/python/xen/xend/XendMonitor.py
tools/python/xen/xend/XendNode.py
tools/python/xen/xend/XendPIF.py

index 2238e60b0511ce5f7f3c9325222854129847f8a1..b9e6dfe1c8d9709b525379d2027c21b82a49874a 100644 (file)
@@ -1448,10 +1448,15 @@ class XendAPI(object):
                                                               'type'))        
 
     def VBD_get_io_read_kbs(self, session, vbd_ref):
-        return xen_api_todo()
+        xendom = XendDomain.instance()
+        return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
+                                                              'io_read_kbs'))
+    
     
     def VBD_get_io_write_kbs(self, session, vbd_ref):
-        return xen_api_todo()
+        xendom = XendDomain.instance()
+        return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
+                                                              'io_read_kbs'))
     
     def VBD_get_all(self, session):
         xendom = XendDomain.instance()
@@ -1553,10 +1558,14 @@ class XendAPI(object):
     
  
     def VIF_get_io_read_kbs(self, session, vif_ref):
-        return xen_api_todo()
-    
+        xendom = XendDomain.instance()
+        return xen_api_success(xendom.get_dev_property_by_uuid('vif', vif_ref,
+                                                               'io_read_kbs'))
+
     def VIF_get_io_write_kbs(self, session, vif_ref):
-        return xen_api_todo()
+        xendom = XendDomain.instance()
+        return xen_api_success(xendom.get_dev_property_by_uuid('vif', vif_ref,
+                                                               'io_write_kbs'))
     
     def VIF_get_all(self, session):
         xendom = XendDomain.instance()
index 587a4dd2e495d8f2c2c33d7df06ef716c937e929..1bc0cb26c2023f0924bba9eb952deb0cf71b29ea 100644 (file)
@@ -49,7 +49,7 @@ PROC_NET_DEV_RE = r'(?P<rx_bytes>\d+)\s+' \
 
 VIF_DOMAIN_RE = re.compile(r'vif(?P<domid>\d+)\.(?P<iface>\d+):\s*' +
                            PROC_NET_DEV_RE)
-PIF_RE = re.compile(r'peth(?P<iface>\d+):\s*' + PROC_NET_DEV_RE)
+PIF_RE = re.compile(r'^\s*(?P<iface>peth\d+):\s*' + PROC_NET_DEV_RE)
 
 # The VBD transfer figures are in "requests" where we don't
 # really know how many bytes per requests. For now we make
@@ -154,10 +154,10 @@ class XendMonitor(threading.Thread):
             if not is_pif:
                 continue
             
-            pifid = int(is_pif.group('iface'))
+            pifname = is_pif.group('iface')
             rx_bytes = int(is_pif.group('rx_bytes'))
             tx_bytes = int(is_pif.group('tx_bytes'))
-            stats[pifid] = (usage_at, rx_bytes, tx_bytes)
+            stats[pifname] = (usage_at, rx_bytes, tx_bytes)
 
         return stats    
 
@@ -297,19 +297,19 @@ class XendMonitor(threading.Thread):
 
                 # Calculate utilisation for PIFs
 
-                for pifid, stats in self._get_pif_stats().items():
-                    if pifid not in self.pifs:
-                        self.pifs[pifid] = stats
+                for pifname, stats in self._get_pif_stats().items():
+                    if pifname not in self.pifs:
+                        self.pifs[pifname] = stats
                         continue
 
                     usage_at, rx, tx = stats
-                    prv_at, prv_rx, prv_tx  = self.pifs[pifid]
+                    prv_at, prv_rx, prv_tx  = self.pifs[pifname]
                     interval = usage_at - prv_at
                     rx_util = (rx - prv_rx)/interval
                     tx_util = (tx - prv_tx)/interval
 
-                    self.pifs_util[pifid] = (rx_util, tx_util)
-                    self.pifs[pifid] = stats
+                    self.pifs_util[pifname] = (rx_util, tx_util)
+                    self.pifs[pifname] = stats
 
                 for domid in self._domain_vcpus_util.keys():
                     if domid not in active_domids:
index 6445914925a13a0b67e5664efd3718bac82aa7cf..713dc081d4ac244427ef9a6ed3e68a4351fb6645 100644 (file)
@@ -482,10 +482,10 @@ class XendNode:
             return vbd_loads[domid].get(vbdid, (0.0, 0.0))
         return (0.0, 0.0)
 
-    def get_pif_util(self, pifid):
+    def get_pif_util(self, pifname):
         pifs_util = self.monitor.get_pifs_util()
-        if pifid in pifs_util:
-            return pifs_util[pifid]
+        if pifname in pifs_util:
+            return pifs_util[pifname]
         return (0.0, 0.0)
 
     # dictionary version of *info() functions to get rid of
index b6f2345c363f34ced717de5a118de4a9bd8ae15e..057d1335ecad7eeb105699f5242780e8fcc43312 100644 (file)
@@ -115,10 +115,12 @@ class XendPIF:
         return success
 
     def get_io_read_kbs(self):
-        return 0.0
+        from xen.xend.XendNode import instance as xennode
+        return xennode().get_pif_util(self.name)[0]
 
     def get_io_write_kbs(self):
-        return 0.0
+        from xen.xend.XendNode import instance as xennode
+        return xennode().get_pif_util(self.name)[1]      
 
     def get_record(self, transient = True):
         result = {'name': self.name,